@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    访问记录
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            @if(!empty($channelId))
                            <a href="/admin/channel/list?app_id={{$appId}}">渠道管理</a>
                            @else
                                <a href="/admin/app/list">应用管理</a>
                            @endif
                        </li>
                        <li class="breadcrumb-item active" aria-current="page">黑名单访问记录列表</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">黑名单访问记录列表</h4>
                            <div class="col-lg-3" style="float: left;padding: 0;">
                            </div>
                            <div class="col-lg-9" style="float: right">
                                <form action="">
                                    <div class="form-group row">
                                        <div class="col-sm-3">
                                            <label class="col-form-label">渠道</label>
                                            <select class="form-control" id="channel_id" name="channel_id">
                                                <option value="0">全部</option>
                                                @foreach($channels as $channelRes)
                                                    <option value="{{$channelRes->id}}" @if($channelId==$channelRes->id)  selected @endif>{{$channelRes->name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <label class="col-form-label">来源</label>
                                            <select class="form-control" id="source_type" name="source_type">
                                                <option value="">全部</option>
                                                <option value="weixin" @if($wd=="weixin")  selected @endif>微信/QQ</option>
                                                <option value="browser" @if($wd=="browser")  selected @endif>浏览器</option>
                                                <option value="refer" @if($wd=="refer")  selected @endif>Refer</option>
                                                <option value="share" @if($wd=="share")  selected @endif>禁止分享</option>
                                                <option value="white" @if($wd=="white")  selected @endif>白名单</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <label class="col-form-label">日期</label><span class="btn btn-danger btn-sm" id="date_sel" style="margin-left: 20px">清空日期</span>
                                            <input class="form-control selector" type="text" name="access_date" id="access_date" value="{{$accessDate}}"/>
                                        </div>
                                        <input type="hidden" name="app_id"  value="{{ $appId }}">
                                        <div class="col-sm-1">
                                            <label class="col-form-label"></label>
                                            <button class="btn btn-sm btn-gradient-primary mb-2" type="submit"><i class="mdi mdi-account-search btn-icon-prepend"></i>
                                                搜索
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>应用名称</th>
                                    <th>渠道名称</th>
                                    <th>记录来源类型</th>
                                    <th>来源记录</th>
                                    <th>创建时间</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $v)
                                    <tr>
                                        <td>{{ $v->id }}</td>
                                        <td>
                                            {{ $v->userApp->name ?? '' }}
                                        </td>
                                        <td>
                                            {{ $v->appChannel->name ?? '' }}
                                        </td>
                                        <td>
                                            @if($v->source_type == "weixin")
                                                <label class="badge badge-success">微信/QQ</label>
                                            @elseif($v->source_type == "browser")
                                                <label class="badge badge-warning">
                                                    @if($v->source_device_type == "pingban")
                                                        平板
                                                    @elseif($v->source_device_type == "pc")
                                                        PC
                                                    @elseif($v->source_device_type == "android")
                                                        安卓
                                                        @if(!empty($v->from_url))
                                                            {{$v->from_url}}
                                                        @endif
                                                    @elseif($v->source_device_type == "iphone")
                                                        苹果
                                                        @if(!empty($v->from_url))
                                                            {{$v->from_url}}
                                                        @endif
                                                    @endif
                                                    浏览器
                                                </label>
                                            @elseif($v->source_type == "refer")
                                                {{ $v->from_url}}
                                            @elseif($v->source_type == "white")
                                                <label class="badge badge-info">非白名单</label>
                                            @elseif($v->source_type == "share")
                                                <label class="badge badge-info">禁止分享</label>
                                            @endif
                                        </td>
                                        <td>
                                            @if($v->source_type == "white")
                                                {{ $v->from_url}}
                                            @else
                                                {{ $v->blackRefer->name ?? ''}}
                                            @endif
                                        </td>
                                        <td>{{ $v->created_at }}</td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                总共 <b>{{ $list->appends(["source_type"=>$wd, "app_id" => $appId,
                                'access_date' => $accessDate,
                                 'channel_id' => !empty($channelId) ? $channelId: 0])->total()  }}</b> 条,分为<b>{{ $list->lastPage() }}</b>页
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="http://cdn.staticfile.org/clipboard.js/2.0.4/clipboard.min.js"></script>
    <script>
        $(function(){
            var clipboard = new ClipboardJS('.btn');

            clipboard.on('success', function(e) {
                layer.msg("链接复制成功!");//弹出提示
                e.clearSelection();
            });

            clipboard.on('error', function(e) {
                layer.msg("链接复制失败，请重试!");//弹出提示
            });
            cutStr(50);
        });
        function add(app_id){
            var page = layer.open({
                type: 2,
                title: '添加渠道',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/channel/add?app_id='+app_id
            });
        }
        function update(id){
            var page = layer.open({
                type: 2,
                title: '修改渠道',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/channel/update/'+id
            });
        }
        function del(id){
            myConfirm("删除操作不可逆,是否继续?",function(){
                myRequest("/admin/channel/del/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        $('.menu-switch').click(function(){
            id = $(this).attr('id');
            state = $(this).attr('state');
            console.log(id)
            console.log(state)
            if(state == "on"){
                $('.pid-'+id).hide();
                $(this).attr("state","off")
                $(this).removeClass('mdi-menu-down').addClass('mdi-menu-right');
            }else{
                $('.pid-'+id).show();
                $(this).attr("state","on")
                $(this).removeClass('mdi-menu-right').addClass('mdi-menu-down');
            }
        })

        $(".selector").flatpickr({});

        $("#date_sel").bind("click", function () {
            $("#access_date").val("");
        })

    </script>
@endsection
